package fem2d;

import fem2.AbstractStructuralStaticDemo;
import fem2.Constraint;
import fem2.Debugger;
import fem2.Element;
import fem2.Force;
import fem2.MaterialModel;
import fem2.Mesh;
import fem2.MeshPart;
import fem2.MeshUtilities;
import fem2.Model;
import fem2.Node;
import fem2.analysis.Analysis;
import fem2.element.NonlinearStructuralElement;
import fem2.enu.EchoLevelType;
import fem2.enu.State;
import fem2.material.StVenantKirchhoffMM;
import fem2.material.SPRrecoveryMM;
import fem2.strategies.ArcLengthSolutionStrategy;
import fem2.strategies.ArcLengthSolutionStrategyWithSphereConstraint;

/**
 * Lshape with structured mesh with mesh is created by joining two meshes
 * 
 * @author hbui
 * 
 */
public class LshapeArcLength extends Lshape {

	public LshapeArcLength() {
		projectDir = "/home/hbui/kratos_janosch";
		projectName = "Lshape.gid";
		meshFileName = "Lshape-structured-arclength";
	}

	@Override
	public Element createElement(MeshPart mp, MaterialModel mm) {
		// return new StructuralElement(mp, mm);
		return new NonlinearStructuralElement(mp, mm);
	}

	@Override
	public Model createConditions(Model m) {
		Mesh mesh = m.getMesh();
		Constraint c1 = new Constraint(false, false);
		mesh.setConstraint(c1, MeshUtilities.seekNodesOnSurface(mesh, 0, 1, -1000));

		Node n = MeshUtilities.seekNode(mesh, 1000, 500);
		Force f = new Force(n, 0, -1e3);
		m.addLoad(f);

		return m;
	}

	@Override
	public MaterialModel createMaterial(Model m) {
		double E = 25850;
		double nu = 0.18;
		double t = 200;
		double rho = 7.85e-6;
		State ss = State.PLANE_STRESS;
		MaterialModel mm = new StVenantKirchhoffMM(E, nu, t, rho, ss);
		return new SPRrecoveryMM(m, mm);
	}

	@Override
	public void run() {
		Model m = createModel();

		Analysis an = new Analysis(m);

		ArcLengthSolutionStrategy s = new ArcLengthSolutionStrategyWithSphereConstraint(m, 1.0, 0.0);

		s.setNumberOfTimeStep(10);

		s.setEchoLevel(EchoLevelType.OUTPUT);

		an.setStrategy(s);

		// addObservers(m, s, null);

		an.run();

		// postProcess(m);

		Debugger.warn("Analysis completed");
	}

	public static void main(String[] args) {
		AbstractStructuralStaticDemo demo = new LshapeArcLength();

		demo.run();
	}
}
